package com.itheima.easy.mapper;

import com.github.pagehelper.Page;
import com.itheima.easy.dto.PendingTasksDto;
import com.itheima.easy.entity.PendingTasks;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/**
* <p>
* todo_tasks Mapper 接口
* </p>
*
* @author sjqn
* @since 2023-06-21 14:53:24
*/
@Mapper
public interface PendingTasksMapper {

    public void insert(PendingTasks todoTasks);

    public Page<List<PendingTasks>> selectByPage(PendingTasksDto pendingTasksDto);

    public void updateByCode(PendingTasks pendingTasks);

    @Select("select * from pending_tasks where code = #{code} and assignee_id = #{assigneeId} and is_handle = 0 ")
    public PendingTasks selectByCode(@Param("code") String code, @Param("assigneeId")Long assigneeId);

    @Select("select * from pending_tasks where code = #{code} and assignee_id = #{assigneeId}")
    public PendingTasks selectByCodeAndAssinessId(@Param("code") String code, @Param("assigneeId")Long assigneeId);

    @Update("update pending_tasks set is_handle = #{isHandle} where code = #{code} and assignee_id = #{assigneeId}")
    void updateIsHandle(@Param("code") String code,@Param("isHandle") Integer isHandle , @Param("assigneeId")Long assigneeId );

    @Update("update pending_tasks set is_handle = #{isHandle} where code = #{code} and assignee_id = #{assigneeId}")
    void updateByCodeAndIsHandle(@Param("code") String code,@Param("isHandle") Integer isHandle , @Param("assigneeId")Long assigneeId );

    @Update("update pending_tasks set is_handle = #{isHandle} where code = #{code}")
    void updateIsHandleByCode(@Param("code") String code,@Param("isHandle") Integer isHandle);

    @Update("update pending_tasks set status = #{status} , finish_time = #{now}  where code = #{code} ")
    void updateStatus(@Param("code") String code,  @Param("now")LocalDateTime now,@Param("status")Integer status);

    @Delete("delete from pending_tasks where code = #{retreatCode} and assignee_id = #{approverId}")
    void deleteByCodeAndAssigneeId(@Param("retreatCode")String retreatCode,@Param("approverId") Long approverId);

    @Delete("delete from pending_tasks where code = #{code}")
    void deleteByCode(String code);

    @Delete("delete from pending_tasks where code = #{code} and is_handle = #{isHandle}")
    void deleteByCodeAndIsHandle(@Param("code")String code,@Param("isHandle") Integer isHandle);

    @Select("select * from pending_tasks where code = #{retreatCode} and step_no = #{stepNo} - 1 ")
    PendingTasks selectByCodeAndStepNo(@Param("retreatCode")String retreatCode, @Param("stepNo")Integer stepNo);

    @Select("select * from pending_tasks where code = #{retreatCode} and step_no = #{stepNo} ")
    PendingTasks selectByRetreatCodeAndStepNo(@Param("retreatCode")String retreatCode, @Param("stepNo")Integer stepNo);

    @Delete("delete from pending_tasks where code = #{retreatCode} and step_no = #{stepNo}")
    void deleteByCodeAndStepNo(@Param("retreatCode")String retreatCode, @Param("stepNo")Integer stepNo);

    @Update("update pending_tasks set  is_handle = #{isHandle}  where code = #{code} and step_no = #{stepNo}")
    void updateIsHandleAndStepNo(@Param("code") String code,@Param("isHandle") Integer isHandle, @Param("stepNo")Integer stepNo);
}